//==================================================================================
//		Dual Quad Board Program
//		file name : Initial_TW2824.H
//		version : 1.0
//		target device : w78e516(winbond)
//		target board : dual quad board
//		c compiler : Keil
//==================================================================================

void Init_Page0();
void Init_Page1();
void Init_Page2();
//void	Set_Mem_Clock(U8);
void Init_Video();

//==================================================================================
//						TW2835 initialize function description
//
//
//
//
//==================================================================================
void Init_Page0()
{
	U8 _t1_;

//	if(BitClear(cmn_flg,CMN_JP_VDO)){
	if(b_cmn_jp_vdo == VDO_NTSC){
		for(_t1_=0;_t1_<4;_t1_++){
			WriteAsicTable(ALL_CHIP,DVC_PG0,0x00+0x10*_t1_,tbl_ntsc_pg0_cmn,15);
			WriteAsicByte(ALL_CHIP,DVC_PG0,0x0c+0x10*_t1_,(_t1_<<6)|0x06);			//... x path ANA_CH mux
			WriteAsicTable(ALL_CHIP,DVC_PG0,0x80+0x10*_t1_,tbl_ntsc_pg0_scl,16);
			WriteAsicByte(ALL_CHIP,DVC_PG0,0x80+0x10*_t1_,(_t1_<<6)|0x01);			//... x path scale filter : quad
//			WriteAsicByte(MASTER,DVC_PG0,0x80+0x10*_t1_,(_t1_<<6)|0x06);			//... x path scale filter : 1/3 size
			WriteAsicByte(ALL_CHIP,DVC_PG0,0x8a+0x10*_t1_,(_t1_<<6)|0x31);			//... y path scale filter : quad
		}

		WriteAsicTable(ALL_CHIP,DVC_PG0,0x40,tbl_ntsc_pg0_sfr1,21);
		WriteAsicTable(ALL_CHIP,DVC_PG0,0x60,tbl_ntsc_pg0_sfr2,21);
		WriteAsicTable(ALL_CHIP,DVC_PG0,0xc0,tbl_ntsc_pg0_sfr3,11);
	}
	else{										//... PAL
		for(_t1_=0;_t1_<4;_t1_++){
			WriteAsicTable(ALL_CHIP,DVC_PG0,0x00+0x10*_t1_,tbl_pal_pg0_cmn,15);
			WriteAsicByte(ALL_CHIP,DVC_PG0,0x0c+0x10*_t1_,(_t1_<<6)|0x06);			//... x path ANA_CH mux
			WriteAsicTable(ALL_CHIP,DVC_PG0,0x80+0x10*_t1_,tbl_pal_pg0_scl,16);
			WriteAsicByte(ALL_CHIP,DVC_PG0,0x80+0x10*_t1_,(_t1_<<6)|0x01);			//... x path scale filter : quad
//			WriteAsicByte(MASTER,DVC_PG0,0x80+0x10*_t1_,(_t1_<<6)|0x06);			//... x path scale filter : 1/3 size
			WriteAsicByte(ALL_CHIP,DVC_PG0,0x8a+0x10*_t1_,(_t1_<<6)|0x31);       //... y path scale filter : quad
		}

		WriteAsicTable(ALL_CHIP,DVC_PG0,0x40,tbl_pal_pg0_sfr1,21);
		WriteAsicTable(ALL_CHIP,DVC_PG0,0x60,tbl_pal_pg0_sfr2,21);
		WriteAsicTable(ALL_CHIP,DVC_PG0,0xc0,tbl_pal_pg0_sfr3,11);
	}
}

//==================================================================================
//
//
//
//
//
//==================================================================================
void Init_Page1()
{
//	U8 _t1_;//, _t2_=0;

//	if(BitClear(cmn_flg,CMN_JP_VDO)){
	if(b_cmn_jp_vdo == VDO_NTSC){
//		WriteAsicTable(ALL_CHIP,DVC_PG1,0x30,tbl_ntsc_pg1_pic_qd,16);		//... normal quad
//		WriteAsicTable(ALL_CHIP,DVC_PG1,0x30,tbl_ntsc_pg1_pic_9_lt,16);		//... non-realtime
//		WriteAsicTable(ALL_CHIP,DVC_PG1,0x40,tbl_ntsc_pg1_pic_9_rb,16);
		WriteAsicTable(ALL_CHIP,DVC_PG1,0xa0,tbl_ntsc_pg1_enc,16);	
		WriteAsicByte(MASTER,DVC_PG1,0x00,0x0c);								//... NTSC
//		WriteAsicByte(MASTER,DVC_PG1,0x7e,0xc9);			//gzy
		WriteAsicByte(SLAVE1,DVC_PG1,0x00,0x3d);			//gzy
//		WriteAsicByte(SLAVE1,DVC_PG1,0x7e,0xc9);			//gzy
	}
	else{
//		WriteAsicTable(ALL_CHIP,DVC_PG1,0x30,tbl_pal_pg1_pic_qd,16);			//... normal quad
//		WriteAsicTable(ALL_CHIP,DVC_PG1,0x30,tbl_pal_pg1_pic_9_lt,16);		//... non-realtime
		//WriteAsicTable(ALL_CHIP,DVC_PG1,0x40,tbl_pal_pg1_pic_9_rb,16);
		WriteAsicTable(ALL_CHIP,DVC_PG1,0xa0,tbl_pal_pg1_enc,16);	

		WriteAsicByte(MASTER,DVC_PG1,0x00,0x8c);			//gzy
//		WriteAsicByte(MASTER,DVC_PG1,0x7e,0xc9);			//gzy
		WriteAsicByte(SLAVE1,DVC_PG1,0x00,0xbd);			//gzy
//		WriteAsicByte(SLAVE1,DVC_PG1,0x7e,0xc9);			//gzy
	}
	WriteAsicTable(ALL_CHIP,DVC_PG1,0x01,tbl_pg1_x_cmn,47);
	WriteAsicTable(ALL_CHIP,DVC_PG1,0x50,tbl_pg1_y_cmn,80);

/*	
	//... queue setting
	for(_t1_=0;_t1_<16;_t1_++){
		//... mux queue
		WriteAsicByte(ALL_CHIP,DVC_PG1,0x59,_t1_);			//... queue data
		WriteAsicByte(ALL_CHIP,DVC_PG1,0x5a,0x80|_t1_);		//... queue addr
		//... popup queue
//		if(_t1_<13){
//			WriteAsicByte(MASTER,DVC_PG1,0x73,(_t1_<<4)|(_t1_+1));			//... queue data
//			WriteAsicByte(MASTER,DVC_PG1,0x74,((_t1_+2)<<4)|(_t1_+3));	//... queue data
//			WriteAsicByte(MASTER,DVC_PG1,0x75,0x80|_t1_);						//... queue addr
//		}
	}
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x73,0x01);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x74,0x23);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x75,0x80);	//... queue addr
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x73,0x12);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x74,0x30);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x75,0x81);	//... queue addr
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x73,0x23);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x74,0x01);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x75,0x82);	//... queue addr
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x73,0x30);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x74,0x12);	//... queue data
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x75,0x83);	//... queue addr
	
	WriteAsicByte(ALL_CHIP,DVC_PG1,0x56,0x40);				//... start internal trigger for mux queue
*/	
}

//==================================================================================
//
//
//
//
//
//==================================================================================
void Init_Page2()
{
	U8 _t1_;

	//... OSD color index
	InitOSDCol();                                              //Initial OSD color that include 12 fixed color and 4 user's defined color via CLUT(1X90-1X9B) (070816)

	
	WriteAsicByte(MASTER,DVC_PG2,0x0f,0x05);//  //Select the OSD reading page0 for display path and Enable bitmap overlay for Display/Capture (070816)	
//	WriteAsicByte(MASTER,DVC_PG2,0x0f,0x0c);		//... OSD Enable for Display				---->> X
//	WriteAsicByte(MASTER,DVC_PG2,0x0f,0x0a);		//... OSD Enable for Display/Capture	//... temporal


	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrX(MASTER,0,0,45,31);						//... max line num is 310 line for OSD

	WriteOSDClrY(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrY(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrY(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrY(MASTER,0,0,45,31);						//... max line num is 310 line for OSD
//	WriteOSDClrY(MASTER,0,0,45,31);						//... max line num is 310 line for OSD


//	WriteAsicByte(MASTER,DVC_PG2,0x10,0xb0);		//... cursor
	WriteAsicByte(MASTER,DVC_PG2,0x10,0x00);		//... Disbale cursor
//	WriteAsicByte(MASTER,DVC_PG2,0x1f,0x00);
	//... other ( mouse, single box, 2d box, mask ..)
	WriteAsicTable(MASTER,DVC_PG2,0x10,tbl_pg2_mse_box,80);
	if(b_video_fmt == NTSC){
		WriteAsicTable(MASTER,DVC_PG2,0x60,tbl_ntsc_pg2_2dbox,32);
		for(_t1_=0;_t1_<4;_t1_++)	WriteAsicTable(MASTER,DVC_PG2,0x80+0x20*_t1_,tbl_ntsc_pg2_mtn,32);
	}
	else{
		WriteAsicTable(MASTER,DVC_PG2,0x60,tbl_pal_pg2_2dbox,32);
		for(_t1_=0;_t1_<4;_t1_++)	WriteAsicTable(MASTER,DVC_PG2,0x80+0x20*_t1_,tbl_pal_pg2_mtn,32);
	}
}

//==================================================================================
//
//
//
//
//
//==================================================================================
void Init_Video()
{
	U8 ntsc_pal_read;
	
	ntsc_pal_read = 1;//I2C_Data_Read(rom_p0, 0x86);		//... NTSC_PAL Select
	
	if(ntsc_pal_read != 0){
		b_video_fmt = PAL;
		cmn_bot = 144;
		cmn_cnt_vs_sub = 45;
	}	
	else{
		b_video_fmt = NTSC;
	       cmn_bot = 120;
		cmn_cnt_vs_sub = 54;
	}
	if(key_code == RIGHT_KEY)
	{
		key_code = 0;
		b_video_fmt = NTSC;
		I2C_Data_Write(rom_p0, 0x86, 0x00);		//... NTSC_PAL Select
	}
	else if(key_code == LEFT_KEY)
	{
		key_code = 0;
		b_video_fmt = PAL;
		I2C_Data_Write(rom_p0, 0x86, 0x01);		//... NTSC_PAL Select
	}
}
//==================================================================================
